package com.test;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Created by 41579 on 2017/4/20.
 */
public class ConditionRunnable implements Runnable{
    private Lock lock = new ReentrantLock();
    private Condition condition = lock.newCondition();
    @Override
    public void run() {
        while(true){
            lock.lock();
            System.out.println(Thread.currentThread().getName());
            try {
                TimeUnit.SECONDS.sleep(3);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            try {
                condition.signalAll();
                condition.await();
                System.out.println(Thread.currentThread().getName()+" 4444");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }finally {
//                System.out.println(Thread.currentThread().getName()+" unlock");
//                lock.unlock();
            }
        }
    }
}
